<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">销售出库</p>
    </div>
    <div class="view-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="批次号" prop="batchNumber">
          <el-input
            v-model="queryParams.batchNumber"
            placeholder="请输入批次号回车或者点击搜索按钮"
            clearable
            size="small"
            style="width:230px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="状态" prop="status" >
          <el-select
            v-model="queryParams.status"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="来源" prop="generateType" >
          <el-select
            v-model="queryParams.generateType"
            placeholder="全部"
            clearable
            size="small"
            style="width:100px;"
          >
            <el-option
              v-for="item in generateType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" class="list-search btn-success" color="#5ED4D4"
            @click="handleQuery"
          >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" class="list-search"
            @click="resetQuery"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="salesList" @row-click="handleView" border>
        <el-table-column label="序号" type="index" align="center" width="50">
           <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="单据编码" align="center" prop="code" :show-overflow-tooltip="true" width="180px" />
        <el-table-column label="产品名称" align="center" prop="productName" :show-overflow-tooltip="true" width="180px" />
        <el-table-column label="产品批号" align="center" prop="batchNumber" :show-overflow-tooltip="true" width="150px" />
        <el-table-column label="产品规格" align="center" prop="productSpace" :show-overflow-tooltip="true" width="180px" />
        <el-table-column :formatter="formatData" label="计划开始时间" align="center" prop="startTime" width="160px" />
        <el-table-column :formatter="formatData" label="计划结束时间" align="center" prop="endTime" width="160px" />
        <el-table-column label="计划出库数量" align="center" prop="planStoreOut" :show-overflow-tooltip="true" width="100px" />
        <el-table-column label="实际出库数量" align="center" prop="storeOut" :show-overflow-tooltip="true" width="100px" />
        <el-table-column label="状态" align="center" prop="status" :show-overflow-tooltip="true" width="100px">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#13C2C2">待出库</div>
            <div v-if="scope.row.status == 1" style="color:#13C2C2">出库中</div>
            <div v-if="scope.row.status == 2" style="color:#52C41A">已完成</div>
          </template>
        </el-table-column>
        <el-table-column label="来源" align="center" prop="generateType" width="100px">
          <template slot-scope="scope">
            <div v-if="scope.row.generateType == 0">PC</div>
            <div v-if="scope.row.generateType == 1">小程序</div>
            <div v-if="scope.row.generateType == 2">销售订单</div>
            <div v-if="scope.row.generateType == 3">oem</div>
            <div v-if="scope.row.generateType == 4">App</div>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark" align="center" :show-overflow-tooltip="true" width="100px" />
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { listProductOutSale } from "@/api/system/outSale/outSale";

export default {
  name: "outSale",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 销售出库数据
      salesList: [],
      // 状态
      status:[
        {
          value:'0',
          label:'待出库'
        },
        {
          value:'1',
          label:'出库中'
        },
        {
          value:'2',
          label:'已完成'
        }
      ],
      // 来源
      generateType:[
        {
          value:'0',
          label:'PC'
        },
        {
          value:'1',
          label:'小程序'
        },
        {
          value:'2',
          label:'销售订单'
        },
        {
          value:'3',
          label:'oem'
        },
        {
          value:'4',
          label:'App'
        }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        //批次号
        batchNumber: undefined,
        status: undefined,
        generateType: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      listProductOutSale(this.addDateRange(this.queryParams)).then(res => {
        this.salesList = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    formatData(row, column, cellValue, index){
      if(cellValue !== null){
        let s = new Date(cellValue).toLocaleString()
        return s
      }
    },
    // 搜索按钮
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    // 重置按钮
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 查看详情
    handleView(row) {
      this.$router.push({path:"/oldOutSale/detail",query:{id: row.id}})
    }
  }
}
</script>
